<?php

namespace Database\Seeders;

use App\Enum\Models\System\Menu\Type;
use App\Models\System\Menu;
use Illuminate\Database\Seeder;

class MenuSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        if (Menu::count() != 0) {
            return;
        }

        $data = [
            [
                'path' => '/dashboard',
                'name' => 'Dashboard',
                'title' => 'page.dashboard.title',
                'code' => 'dashboard',
                'type' => Type::Catalog,
                'children' => [
                    [
                        'name' => 'Analytics',
                        'path' => '/analytics',
                        'title' => 'page.dashboard.analytics',
                        'code' => 'dashboard.analytics',
                        'component' => '/dashboard/analytics/index',
                        'type' => Type::Menu,
                        'meta' => [
                            'affixTab' => true,
                        ],
                    ],
                    [
                        'name' => 'Workspace',
                        'path' => '/workspace',
                        'title' => 'page.dashboard.workspace',
                        'code' => 'dashboard.analytics',
                        'component' => '/dashboard/workspace/index',
                        'type' => Type::Menu,
                    ],
                ],
            ],
            [
                'path' => '/system',
                'title' => '系统管理',
                'name' => 'system',
                'type' => Type::Catalog,
                'code' => 'system',
                'meta' => [
                    'icon' => 'icon-setting',
                ],
                'children' => [
                    [
                        'path' => '/system/menu',
                        'title' => '菜单管理',
                        'name' => 'SystemMenu',
                        'component' => '/system/menu/index',
                        'code' => 'system.menu',
                        'type' => Type::Menu,
                    ],
                ],
            ],
        ];
        // 开启字段过滤 数据库迁移会自动关闭
        Menu::unguard(false);
        Menu::createTree($data);
        // 执行完后关闭
        Menu::unguard(true);
    }
}
